<template>
  <Card v-style="'boxstyle_bg_1'" title="网站排名">
    <div class="list">
      <p v-for="(item,index) in dataList" :key="index">
        <span class="tab">{{ index + 1}}</span>
        <span v-title>{{ item.url }}</span>
      </p>
    </div>
  </Card>
</template>

<script lang="ts" setup>
import { ref, onMounted, defineProps, toRefs, watch } from "vue";
import Card from "@/components/Card";
import { bigDataApi } from "@/api/bigData";
import store from "@/store";
onMounted(() => {
  // getList();
});
const dataList = ref([]);

let selectWord = ref('');


const porps = defineProps({
  keyword: {
    type: String,
    default: ''
  }
})

const { keyword } = toRefs(
  porps
);

watch(
  keyword,
  (e) => {
    console.log(e)
    selectWord = e
    if(e){
      getList()
    }
  },
  {
    immediate: true,
  }
);

async function getList() {
  const result = await bigDataApi.detail({
    token: store.getters.user.token,
    keyword: selectWord
  });
  const { data } = result;
  dataList.value = data['website_ranking']
  console.log(dataList)
}

</script>

<style lang="less" scoped>
.list {
  height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: flex-start;

  p {
    width: 33%;
    background: #151515;
    border-radius: 5px;
    padding: 10px;
    margin-bottom: 10px;
    margin-right: 10px;
    .tab {
      font-size: 14px;
      background: #404143;
      border-radius: 6px;
      width: 20px;
      height: 20px;
      text-align: center;
      display: inline-block;
      margin-right: 10px;
    }
  }
  p:nth-child(1) {
    .tab {
      background: #f40000;
    }
  }
  p:nth-child(2) {
    .tab {
      background: #f79200;
    }
  }
  p:nth-child(3) {
    .tab {
      background: #f1ca00;
    }
  }
}
</style>
